package com.tiger.service.websocket;

import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;

/**
 * @author HuXuehao (StudiousTiger)
 * @desc 这个类的作用是
 * @date 2022/3/17
 */
public class GetHttpSessionConfigurator extends ServerEndpointConfig.Configurator {
    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        // 获取 httpSession
        HttpSession httpSession = (HttpSession) request.getHttpSession();

        // 将 httpSession 存到 EndpointConfig 中 （ServerEndpointConfig 继承了 EndpointConfig）
        // key 使用 HttpSession 字节码的名称进行唯一的标识
        sec.getUserProperties().put(HttpSession.class.getName(),httpSession);

    }
}
